local joyex__fuli = fk.CreateSkill {

  name = "joyex__fuli",

  tags = { Skill.Limited, },

}



joyex__fuli:addEffect(fk.AskForPeaches, {
  name = "joyex__fuli",
  anim_type = "defensive",
  frequency = Skill.Limited,
  events = {fk.AskForPeaches},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(joyex__fuli.name) and player.dying and player:usedSkillTimes(joyex__fuli.name, Player.HistoryGame) == 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, joyex__fuli.name, 1)
    local kingdoms = {}
    for _, p in ipairs(room:getAlivePlayers()) do
      table.insertIfNeed(kingdoms, p.kingdom)
    end
    room:recover({
      who = player,
      num = math.min(#kingdoms, player.maxHp) - player.hp,
      recoverBy = player,
      skillName = joyex__fuli.name
    })
    if player:getHandcardNum() < #kingdoms and not player.dead then
      player:drawCards(#kingdoms - player:getHandcardNum())
    end
    if #kingdoms > 3 and not player.dead then
      player:turnOver()
    end
  end,
})

return joyex__fuli